package parking.service;

import java.util.Collections;
import java.util.List;
import java.util.StringJoiner;

public interface ParkReport {

    default String report(){
       return report(0);
    }

    /**
     * 打印行
     *
     * @return string
     */
    default String reportSelf(){
        return String.format("%s %d %d",getType(),getHasCar(),getTotalSpace());
    }

    /**
     * 指定层级打印
     * @param level 层级
     * @return String
     */
   default String report(int level){
       StringJoiner stringJoiner = new StringJoiner("\n");
       stringJoiner.add(addPrefix(level,reportSelf()));
       //处理子停车场
       getChildren()
               .forEach(parkLot ->
                       stringJoiner.add(parkLot.report(level + 1)));
       return stringJoiner.toString();
   }

    /**
     *
     *
     * @param level 层级
     * @param reportLine 打印行
     * @return
     */
   default String addPrefix(int level,String reportLine){
       String prefix = String.join("", Collections.nCopies(level," "));
       return String.format("%s%s",prefix,reportLine);
   }

    /**
     * 获取子车场
     *
     */
    List<ParkReport> getChildren();

    /**
     * 获取类型
     * @return String
     */
    String getType();

    /**
     * 已停车辆
     *
     * @return int
     */
    int getHasCar();

    /**
     * 总停车位
     *
     * @return int
     */
    int getTotalSpace();
}
